﻿Ext.ns('sys.rd');

sys.rd.username = function(value, p, record) {
	if (sys.guest) return value;
	return String.format(
			'<a href="javascript:void(0);" onclick="showUser(\'{0}\');" class="likelink">{0}</a>',
			value);
};
sys.rd.author = function(value, p, record) {
	if (sys.guest) return getauthor(value, record.data.nickname);
	return String
			.format(
					'<a href="javascript:void(0);" onclick="showUser(\'{1}\');" title="{1}" class="likelink"{2}>{0}</a>',
					getauthor(value, record.data.nickname), record.data.username, record.data.god
							? ' style="color:red"'
							: '');
};

sys.rd.pid = function(value, p, record) {
	if (sys.guest) return value;
	return String
			.format(
					'<a href="javascript:void(0);" onclick="showProblem({0});" title="{1}" class="likelink">{0}</a>',
					value, record.data.problemTitle.replace(/"/g, '\''));
};
sys.rd.rid = function(value, p, record) {
	if (sys.guest) return value;
	return String.format(
			'<a href="javascript:void(0);" onclick="showStatus({0});" class="likelink">{0}</a>',
			value);
};

sys.rd.status = function(value, p, record) {
	if (sys.user) {
		if (record.data.statusCode == 9 && (record.data.allowCode || sys.god))
			return String
					.format(
							'<a href="javascript:void(0);" onclick="alertx(\'{1} ({2})\')" title="{1} ({2})" class="likelink" style="font-weight:bold">{0}</a>',
							value, record.data.reInfo, record.data.reCode);
		else if (record.data.statusCode == 10 && (record.data.allowCode || sys.god))
			return String
					.format(
							'<a href="javascript:void(0);" onclick="alertx(unescape(\'{1}\'));" title="点击查看错误信息" class="likelink" style="font-weight:bold">{0}</a>',
							value, escape(HTMLEncode(record.data.ceInfo)));
	}
	return String.format('<span style="font-weight:bold">{0}</span>', value);
};
sys.rd.codelen = function(value, p, record) {
	if (sys.guest || !sys.god && !record.data.allowCode) return value + ' B';
	return String
			.format(
					'<a href="javascript:void(0);" onclick="showCode({1});" title="点击查看代码" class="likelink">{0}</a> B',
					value, record.data.rid);
};
sys.rd.exetime = function(value, p, record) {
	return Ext.isEmpty(value) ? '' : value + ' MS';
};
sys.rd.exemem = function(value, p, record) {
	return Ext.isEmpty(value) ? '' : value + ' KB';
}
sys.rd.yesno = function(value, p, record) {
	return value ? '<span style="color:red">是</span>' : '否';
};
sys.rd.sex = function(value, p, record) {
	return !value ? '' : value == 1 ? '男' : '女';
};
sys.rd.acsubmit = function(value, p, record) {
	return String.format('{0} / {1}', record.data.accept, value);
}

sys.rd.colors = ['#00ff00', '#FFFF00', '#FF0000', '#FFA500', '#A9A9A9', '#0000FF', '#00FFFF',
		'#DA70D6', '#8B4513'];
sys.rd.getcolor = function(code) {
	if (code >= 20)
		return '#000000';
	else
		return sys.rd.colors[code - 3];
}
sys.rd.colorstatus = function(value, p, record) {
	return String.format('<span style="color:{1};font-weight:bold">{0}</span>', value, sys.rd
					.getcolor(record.data.code));
};

sys.rd.ratio = function(ac, submit) {
	if (ac == 0 && submit == 0) return '0%';
	return (parseInt(ac * 10000.0 / submit + 0.5) / 100.0).toString() + '%';
}

function getauthor(username, nickname) {
	return Ext.isEmpty(nickname) ? username : nickname;
}
sys.rd.authorusername = function(user) {
	return Ext.isEmpty(user.nickname) ? user.username : user.nickname == user.username
			? user.username
			: user.nickname + ' (' + user.username + ')';
}

// 数据结构
sys.rd.DSpid = function(value, p, record) {
	if (sys.guest) return value;
	return String
			.format(
					'<a href="javascript:void(0);" onclick="showDSProblem({pid:{0},eid:{2}});" title="{1}" class="likelink">{0}</a>',
					value, record.data.problemTitle.replace(/"/g, '\''), record.data.eid);
};
sys.rd.DSrid = function(value, p, record) {
	if (sys.guest) return value;
	return String.format(
			'<a href="javascript:void(0);" onclick="showDSStatus({0});" class="likelink">{0}</a>',
			value);
};
sys.rd.DSstatus = function(value, p, record) {
	if (sys.user) {
		if (record.data.statusCode == 9 && (record.data.allowCode || sys.god || sys.teacher))
			return String
					.format(
							'<a href="javascript:void(0);" onclick="alertx(\'{1} ({2})\')" title="{1} ({2})" class="likelink" style="font-weight:bold">{0}</a>',
							value, record.data.reInfo, record.data.reCode);
		else if (record.data.statusCode == 10 && (record.data.allowCode || sys.god))
			return String
					.format(
							'<a href="javascript:void(0);" onclick="alertx(unescape(\'{1}\'));" title="点击查看错误信息" class="likelink" style="font-weight:bold">{0}</a>',
							value, escape(HTMLEncode(record.data.ceInfo)));
	}
	return String.format('<span style="font-weight:bold">{0}</span>', value);
};
sys.rd.DScodelen = function(value, p, record) {
	if (sys.guest || !sys.god && !sys.teacher && !record.data.allowCode) return value + ' B';
	return String
			.format(
					'<a href="javascript:void(0);" onclick="showDSCode({1});" title="点击查看代码" class="likelink">{0}</a> B',
					value, record.data.rid);
};